<?php
require_once('libs/controller.php');

class LController extends Controller{

	public $data;
	public $stores;
	public $store;
	public function category() {
		require_once('components/com_shop/models/shop_category.php');
		$cate = new ShopCategoryModel();
		$task = Helper::checkTask('index.php?com=com_shop&view=categories');
		if (!empty($_POST)) {
			$data = $_POST;
			if ($cate->$task($data)) {
				header('Location: index.php?com=com_shop&view=categories');
				exit();
			}
		}
		$optionCategory = '';
		$cate->optionCategory(0, '--', $optionCategory);
		$this->data = array(
			'optionCategory' => $optionCategory
		);
	}

	public function categories() {

	}
	public function store() {
		require_once('components/com_shop/models/shop_store.php');
		$model = new ShopStoreModel();
		$task = $_GET['task'];
		if (!empty($_POST)) {
			$data = $_POST;
			$model->$task($data);
			header('Location: index.php?com=com_shop&view=stores');
			exit();
		}
		if ($task == 'update' && !empty($_GET['id']) ){
			$this->store = $model->getStore($_GET['id']);
			if (!empty($_POST)) {
				$data = $_POST;
				$model->$task($data);
				header('Location: index.php?com=com_shop&view=stores');
				exit();
			}
		}
	}
	
	public function stores() {
		require_once('components/com_shop/models/shop_store.php');
		$model = new ShopStoreModel();
		$this->stores = $model ->getList();
		if (!empty($_POST)) {
				$task = $_POST['task'];
				$model->$task($_POST['id']);
				header('Location: index.php?com=com_shop&view=stores');
				exit();
		}
	}
}